/**
 * Class ReferrerFlowModule.
 * 
 * @author Maxime Ollagnier
 */
ReferrerFlowModule.inherits(Module);
function ReferrerFlowModule () {
	var that = this;
	
	this.referrer = undefined;
	this.inheritedMandateFlows = undefined;
	this.mandateFlows = undefined;
	this.mandateFlowTable = undefined;
	this.mandateFlow = undefined;
	this.availableCustomProperties = undefined;

	/** Mandate flow form */
	this.inputName = new InputTextModule({
		'id' : 'inputName',
		'label' : I18n.get('name'),
		'placeholder' : I18n.get('name'),
		'validationPattern' : ValidationPattern.VALID_DEFAULT,
		'mandatory' : true,
		'onKeyUp' : function() { that.setJQFormTitle(); },
		'onEnter' : function() { that.saveMandateFlow(); }
	});
	this.inputCreatedStatus = new InputCheckboxModule({
		'id' : 'inputCreatedStatus',
		'label' : I18n.get('referrer.mandateFlow.createdStatus'),
		'onChange' : function() { that.setJQFormTitle(); },
		'widthClass' : 'input-mini'
	});
	this.inputWaitingSignatureStatus = new InputCheckboxModule({
		'id' : 'inputWaitingSignatureStatus',
		'label' : I18n.get('referrer.mandateFlow.waitingSignatureStatus'),
		'onChange' : function() { that.setJQFormTitle(); },
		'widthClass' : 'input-mini'
	});
	this.inputDefaultStatus = new InputCheckboxModule({
		'id' : 'inputDefaultStatus',
		'label' : I18n.get('referrer.mandateFlow.defaultStatus'),
		'onChange' : function() { that.setJQFormTitle(); },
		'widthClass' : 'input-mini'
	});
	this.inputActiveStatus = new InputCheckboxModule({
		'id' : 'inputActiveStatus',
		'label' : I18n.get('referrer.mandateFlow.activeStatus'),
		'onChange' : function() { that.setJQFormTitle(); },
		'widthClass' : 'input-mini',
		'onChange' : function(selected){
			that.inputDefaultStatus.setReadonly(!selected).buildJQ();
			if (!selected){
				that.inputDefaultStatus.setValue(false).buildJQ();
			}
		}
	});
	/** collapsible module for Mandate notification */
	this.notificationCollapsible = new CollapsibleModule({
		'title' : $('<h5>' + I18n.get('mandate.notification') + '</h5>'),
		'showCollapsibleIcon' : 'prepend',
		'collapsed' : true,
		'effect' : 'slide'
	});
	this.notificationCollapsible.inputNotif = new InputCheckboxModule({
		'label' : I18n.get('referrer.mandateFlow.notification'),
		'onChange' : function() { that.notificationCollapsible.inputNotifDelay.setReadonly(!that.notificationCollapsible.inputNotif.getValue()).buildJQ(); },
		'widthClass' : 'input-mini'
	});
	this.notificationCollapsible.inputNotifDelay = new InputTextModule({
		'label' : I18n.get('referrer.mandateFlow.notification.delay'),
		'placeholder' : I18n.get('referrer.mandateFlow.notification.delay.placeholder'),
		'validationPattern' : ValidationPattern.VALID_NOTIF_DELAY,
		'value' : 3,
		'readonly' : true,
		'widthClass' : 'input-mini'
	});
	this.inputMadatoryValues = new InputMultipleValueSelectModule({
		'id' : 'inputMadatoryValues',
		'label' : I18n.get('referrer.mandateFlow.mandatoryFields'),
		'inputLabel' : I18n.get('referrer.mandateFlow.addField'),
		'options' : $.extend({}, EnumManager.ConformityProperty, this.availableCustomProperties),
		'unique' : true,
		'onChange' : function() { that.setJQFormTitle(); },
		'getText' : function(value, object) {
			// If the object is a simple String (standard non SEPA mandatory field)
			if (Util.checkString(object)) {
				return I18n.get(value);
			}
			// If the object is a custom property
			return object.name;
		}
	});
	this.inputFixedValues = new InputMultipleValueSelectModule({
		'id' : 'inputFixedValues',
		'label' : I18n.get('referrer.mandateFlow.fixedFields'),
		'inputLabel' : I18n.get('referrer.mandateFlow.addField'),
		'options' : $.extend({}, EnumManager.FixedProperty, this.availableCustomProperties),
		'unique' : true,
		'onChange' : function() { that.setJQFormTitle(); },
		'getText' : function(value, object) {
			// If the object is a simple String (standard SEPA field)
			if (Util.checkString(object)) {
				return I18n.get(value);
			}
			// If the object is a custom property
			return object.name;
		}
	});
	this.inputFixedValuesMandateStatus = new InputSelectModule({
		'id' : 'inputFixedValuesMandateStatus',
		'label' : I18n.get('referrer.mandateFlow.mandatoryFieldsMandateStatus'),
		'options' : EnumManager.mandateStatusNonUpdatableField,
		'value' : "Compliant"
	});
	
	/** collapsible module for Mandate models */
	this.mandateModelCollapsible = new CollapsibleModule({
		'title' : $('<h5>' + I18n.get('mandate.models') + '</h5>'),
		'showCollapsibleIcon' : 'prepend',
		'collapsed' : true,
		'effect' : 'slide'
	});
	this.mandateModels = new MandateModelModule();
}

ReferrerFlowModule.neededRoles = ['MANAGE_MANDATEFLOW'];

ReferrerFlowModule.prototype.fillJQ = function(jQ) {
	var that = this;
	
	// List title
	jQ.append($('<h5>' + I18n.get('referrer.mandateFlow.list') + '</h5>'));
	
	// New button
	if (UserManager.hasRoles(['MANAGE_MANDATEFLOW'])) {
		var buttonNew = $('<div class="btn new">' + I18n.get('new') + ' <i class="icon-plus icon"/></div>');
		buttonNew.click(function() { that.newMandateFlow(); });
		jQ.find('h5:first').append(buttonNew);
	}
	
	// Mandate flows table
	jQ.append(this.mandateFlowTable.buildJQ());
	
	// Mandate flow edition form
	this.jQForm = $('<div id="mandateFlowEditionForm"></div>').hide();
	jQ.append(this.jQForm);
	
	// Fills form with selected mandate flow
	if (Util.checkObject(this.mandateFlowTable.selectedObject)) {
		this.editMandateFlow(this.mandateFlowTable.selectedObject.id);
	}
};

/**
 * Fills the JQ representation of the mandate flow edition form
 */
ReferrerFlowModule.prototype.fillJQForm = function() {
	var that = this;
	
	// Form title
	this.setJQFormTitle();
	
	// Form
	var form = $('<div class="form well"></div>');
	this.jQForm.append(form);

	var row1 = $('<div class="row-fluid"></div>');
	var columnLeft = $('<div class="span6"></div>');
	columnLeft.append(this.inputName.buildJQ());
	var columnRight = $('<div class="span6"></div>');
	var checkboxRow = $('<div class="row-fluid"></div>');
	checkboxRow.append(this.inputCreatedStatus.buildJQ().addClass('span6'));
	checkboxRow.append(this.inputWaitingSignatureStatus.buildJQ().addClass('span6'));
	checkboxRow.append(this.inputDefaultStatus.buildJQ().addClass('span6 no-margin'));
	if (!UserManager.isCreditor(this.referrer)){
		this.inputDefaultStatus.buildJQ().addClass('not-visible');
	}
	checkboxRow.append(this.inputActiveStatus.buildJQ().addClass('span6'));
	this.inputActiveStatus.onChange(this.inputActiveStatus.value);
	columnRight.append(checkboxRow);
	form.append(row1.append(columnLeft).append(columnRight));
	
	form.append($('<hr>'));
	
	var row2 = $('<div class="row-fluid"></div>');
	var column = $('<div class="span12" style="min-height:0"></div>');
	column.append(this.inputMadatoryValues.buildJQ());
	form.append(row2.append(column));

	form.append($('<hr>'));
	
	var row2Bis = $('<div class="row-fluid"></div>');
	var column = $('<div class="span12" style="min-height:0"></div>');
	column.append(this.inputFixedValues.buildJQ());
	form.append(row2Bis.append(column));
	column = $('<div class="span6" style="min-height:0;margin-left:0;margin-top:15px;"></div>');
	column.append(this.inputFixedValuesMandateStatus.buildJQ());
	form.append(row2Bis.append(column));
	

	form.append($('<hr>'));
	
	// Notifications
	var row3 = $('<div class="row-fluid"></div>');
	columnLeft = $('<div class="span6"></div>');
	columnLeft.append(this.notificationCollapsible.inputNotif.buildJQ());
	columnLeft.append(this.notificationCollapsible.inputNotifDelay.buildJQ());
	this.notificationCollapsible.setContent(row3.append(columnLeft));
	form.append(this.notificationCollapsible.buildJQ());
	
	// Mandate model module
	if (UserManager.hasRoles(['MANAGE_CREDITOR'])) {
		form.append($('<hr>'));
		form.append(that.mandateModelCollapsible.buildJQ());
		if (Util.check(this.mandateFlow.id)){
			this.mandateModels.setReadonly(Util.checkBoolTrue(this.mandateFlow.inherited));
			this.mandateModels.load({
				'mandateFlowId' : this.mandateFlow.id
			}, function(jQ) {
				if (jQ.data('module').mandateModelTable.objectMap.size > 0 || !that.mandateFlow.inherited) {
					that.mandateModelCollapsible.setContent(jQ);
					that.mandateModelCollapsible.buildJQ();
				}
			});
		}
	}
	
	// Buttons
	var buttonRow = $('<div class="btn-row"></div>');
	form.append(buttonRow);
	
	//if type is entity and flow is inherited, don't display save button
	if (UserManager.isCreditor(this.referrer) || !that.mandateFlow.inherited){
		// and if it a creditor, flow is inherited and inactive, don't display the save button
		if (!(UserManager.isCreditor(this.referrer) && that.mandateFlow.inherited && !that.mandateFlow.activeStatus)){
			var buttonSave = $('<div class="btn save">' + I18n.get('save') + '</div>');
			buttonSave.click(function() { 
				if (!that.mandateFlow.inherited){
					that.saveMandateFlow();
				} else {
					that.saveDefaultMandateFlow();
				}
			});
			buttonRow.append(buttonSave);
		}
	}
};

/**
 * Sets the mandate flow edition form title
 */
ReferrerFlowModule.prototype.setJQFormTitle = function() {
	var jQFormTitle = this.jQForm.children('h5:first');
	if (!Util.checkJQueryNotEmpty(jQFormTitle)) {
		jQFormTitle = $('<h5></h5>');
		this.jQForm.prepend(jQFormTitle);
	}
	jQFormTitle.clear();
	if (!Util.checkStringNotEmpty(this.mandateFlow.name)) {
		jQFormTitle.text(I18n.get('referrer.mandateFlow.new'));
	} else {
		jQFormTitle.text(I18n.get('referrer.mandateFlow'));
		if (this.mandateFlow.inherited) {
			jQFormTitle.addClass('inherited');
			jQFormTitle.append(' (' + I18n.get('referrer.mandateFlow.inherited') + ' - ' + I18n.get('readonly') + ')');
		}
		jQFormTitle.append(' - ' + this.mandateFlow.name);
	}
	if (this.isMandateFlowModified()) {
		jQFormTitle.addClass('modified');
		jQFormTitle.append(' *');
	} else {
		jQFormTitle.removeClass('modified');
	}
};

/**
 * Returns true if any modification of in the mandate flow edition form is pending
 */
ReferrerFlowModule.prototype.isMandateFlowModified = function() {
	return 	this.inputName.modified ||
			this.inputCreatedStatus.modified ||
			this.inputWaitingSignatureStatus.modified ||
			this.inputDefaultStatus.modified ||
			this.inputActiveStatus.modified ||
			this.inputMadatoryValues.modified ||
			this.inputFixedValues.modified;
};

/**
 * Loads the referrer, its mandate flows and its inherited mandate flows
 */
ReferrerFlowModule.prototype.loadData = function(callback) {
	var that = this;
	
	// Sets the referrer
	this.referrer = this.parameters.referrer;
	
	this.mandateFlowTable = this.getMandateFlowTable();
	// Resets the mandate flows table object map
	this.mandateFlowTable.objectMap = new Map();
	
	// Fetches the inherited mandate flows from server
	AjaxManager.getJSON("getInheritedMandateFlows", {
		'referrerId' : this.referrer.id
	}, function(result) {
		if (result.success) {
			// Saves the inherited mandate flows
			that.inheritedMandateFlows = result.inheritedMandateFlows;
			
			// Sets the inherited mandate flows
			$.each(that.inheritedMandateFlows, function(id, inheritedMandateFlow) {
				that.mandateFlowTable.objectMap.put(id, inheritedMandateFlow);
			});
		}
		// Fetches the mandate flows from server
		AjaxManager.getJSON("getMandateFlows", {
			'referrerId' : that.referrer.id
		}, function(result) {
			if (result.success) {
				// Saves the mandate flows
				that.mandateFlows = result.mandateFlows;
				
				// Sets the mandate flows
				$.each(that.mandateFlows, function(id, mandateFlow) {
					that.mandateFlowTable.objectMap.put(id, mandateFlow);
				});
			}
			// Fetches the available custom properties for the referrer from the server
			AjaxManager.getJSON("getAvailableCustomProperties", {
				'referrerId' : that.referrer.id
			}, function(result) {
				if (result.success) {
					// Saves the available custom properties
					that.availableCustomProperties = result.availableCustomProperties;
					
					// Sets the options of the mandatory properties select
					that.inputMadatoryValues.setOptions($.extend({}, EnumManager.ConformityProperty, that.availableCustomProperties));
					
					// Sets the options of the fixed properties select
					that.inputFixedValues.setOptions($.extend({}, EnumManager.FixedProperty, that.availableCustomProperties));
					
					// Sets the selected object of the mandate flow table
					if (Util.checkObject(that.mandateFlowTable.selectedObject)) {
						that.mandateFlowTable.selectedObject = that.mandateFlowTable.objectMap.get(that.mandateFlowTable.selectedObject.id);
					}
				}
				Util.getFunction(callback)();
			});
		});
	});
};

/**
 * Sets the edited mandate flow
 */
ReferrerFlowModule.prototype.setMandateFlow = function(mandateFlow) {
	mandateFlow = Util.getObject(mandateFlow);
	if (this.mandateFlow != mandateFlow) {
		this.mandateFlow = mandateFlow;
		if (Util.checkBoolTrue(this.mandateFlow.inherited)) {
			this.inputName.setReadonly(true);
			this.inputCreatedStatus.setReadonly(true);
			this.inputWaitingSignatureStatus.setReadonly(true);
			this.inputMadatoryValues.setReadonly(true);
			this.inputDefaultStatus.setReadonly(true);
			this.inputActiveStatus.setReadonly(true);
			this.inputFixedValues.setReadonly(true);
			this.inputFixedValuesMandateStatus.setReadonly(true);
			this.notificationCollapsible.inputNotif.setReadonly(true);
			this.notificationCollapsible.inputNotifDelay.setReadonly(true);
		} else {
			this.inputName.setReadonly(false);
			this.inputCreatedStatus.setReadonly(false);
			this.inputWaitingSignatureStatus.setReadonly(false);
			this.inputDefaultStatus.setReadonly(false);
			this.inputActiveStatus.setReadonly(false);
			this.inputMadatoryValues.setReadonly(false);
			this.inputFixedValues.setReadonly(false);
			this.inputFixedValuesMandateStatus.setReadonly(false);
			this.notificationCollapsible.inputNotif.setReadonly(false);
			this.notificationCollapsible.inputNotifDelay.setReadonly(false);
		}
		this.inputName.modified = false;
		this.inputCreatedStatus.modified = false;
		this.inputWaitingSignatureStatus.modified = false;
		this.inputDefaultStatus.modified = false;
		this.inputActiveStatus.modified = false;
		this.inputMadatoryValues.modified = false;
		this.inputFixedValues.modified = false;
		this.inputFixedValuesMandateStatus.modified = false;
		this.notificationCollapsible.inputNotif.modified = false;
		this.notificationCollapsible.inputNotifDelay.modified = false;
		
		this.inputName.setValue(this.mandateFlow.name);
		this.inputCreatedStatus.setValue(this.mandateFlow.createdStatus);
		this.inputWaitingSignatureStatus.setValue(this.mandateFlow.waitingSignatureStatus);
		this.inputDefaultStatus.setValue(this.mandateFlow.defaultStatus);
		this.inputActiveStatus.setValue(this.mandateFlow.activeStatus);
		this.notificationCollapsible.inputNotif.setValue(this.mandateFlow.evidenceNotif);
		this.notificationCollapsible.inputNotifDelay.setValue(this.mandateFlow.evidenceDelay);
		this.notificationCollapsible.inputNotifDelay.setReadonly(!this.notificationCollapsible.inputNotif.value);
		if (this.notificationCollapsible.inputNotifDelay.value === ''){
			this.notificationCollapsible.inputNotifDelay.setValue(3);
		}
		if (Util.checkArray(this.mandateFlow.mandatoryProperties)) {
			this.inputMadatoryValues.setValues(this.mandateFlow.mandatoryProperties.concat(this.mandateFlow.mandatoryCustomProperties));
		} else {
			this.inputMadatoryValues.setValues();
		}
		if (Util.checkArray(this.mandateFlow.fixedProperties)) {
			this.inputFixedValues.setValues(this.mandateFlow.fixedProperties.concat(this.mandateFlow.fixedCustomProperties));
		} else {
			this.inputFixedValues.setValues();
		}
		this.inputFixedValuesMandateStatus.setValue(this.mandateFlow.fixFieldsStatusChanged);
	}
};

/**
 * Edit a new mandate flow
 */
ReferrerFlowModule.prototype.newMandateFlow = function() {
	this.mandateFlowTable.unselect();
	this.setMandateFlow();
	this.jQForm.clear();
	this.inputActiveStatus.setValue(true);
	this.fillJQForm();
	this.jQForm.show();
};

/**
 * Edit a mandate flow
 */
ReferrerFlowModule.prototype.editMandateFlow = function(mandateFlowId) {
	this.jQForm.clear();
	if (!Util.check(mandateFlowId)) {
		this.jQForm.hide();
		return;
	}
	var editedMandateFlow = this.mandateFlows[mandateFlowId];
	if (!Util.checkObject(editedMandateFlow)) {
		editedMandateFlow = this.inheritedMandateFlows[mandateFlowId];
	}
	this.setMandateFlow(editedMandateFlow);
	this.fillJQForm();
	this.jQForm.show();
};

/**
 * Deletes a mandate flow
 */
ReferrerFlowModule.prototype.deleteMandateFlow = function(mandateFlowId) {
	
	var that = this;
	AjaxManager.getJSON('deleteMandateFlow', {
		'referrerId' : this.referrer.id,
		'id' : mandateFlowId
	}, function(result) {
		if (result.success) {
			delete that.mandateFlows[mandateFlowId];
			that.mandateFlowTable.unselect();
			that.reload();
		}
	});
	return true;
};

/**
 * Save a mandate flow
 */
ReferrerFlowModule.prototype.saveMandateFlow = function() {
	if(!this.validate()) {
		return;
	}
	
	var mandateFlow = {};
	mandateFlow.id = this.mandateFlow.id;
	mandateFlow.name = this.inputName.value;
	mandateFlow.referrerId = this.referrer.id;
	
	mandateFlow.evidenceNotif = this.notificationCollapsible.inputNotif.value;
	mandateFlow.evidenceDelay = this.notificationCollapsible.inputNotifDelay.value;
	
	mandateFlow.createdStatus = this.inputCreatedStatus.value;
	mandateFlow.waitingSignatureStatus = this.inputWaitingSignatureStatus.value;
	mandateFlow.defaultStatus = this.inputDefaultStatus.value;
	mandateFlow.activeStatus = this.inputActiveStatus.value;
	
	mandateFlow.fixFieldsStatusChanged = this.inputFixedValuesMandateStatus.value;
	
	mandateFlow.mandatoryProperties = [];
	mandateFlow.mandatoryCustomProperties = [];
	for (var i = 0; i < this.inputMadatoryValues.values.length; i++) {
		if (Util.checkString(EnumManager.ConformityProperty[this.inputMadatoryValues.values[i]])) {
			mandateFlow.mandatoryProperties.push(this.inputMadatoryValues.values[i]);
		}
		else if (Util.checkObject(this.availableCustomProperties[this.inputMadatoryValues.values[i]])) {
			mandateFlow.mandatoryCustomProperties.push(this.inputMadatoryValues.values[i]);
		}
	}

	mandateFlow.fixedProperties = [];
	mandateFlow.fixedCustomProperties = [];
	for (var i = 0; i < this.inputFixedValues.values.length; i++) {
		if (Util.checkString(EnumManager.FixedProperty[this.inputFixedValues.values[i]])) {
			mandateFlow.fixedProperties.push(this.inputFixedValues.values[i]);
		}
		else if (Util.checkObject(this.availableCustomProperties[this.inputFixedValues.values[i]])) {
			mandateFlow.fixedCustomProperties.push(this.inputFixedValues.values[i]);
		}
	}
	
	var that = this;
	AjaxManager.getJSON('saveMandateFlow', {
		'newMandateFlow' : JSON.stringify(mandateFlow)
	}, function(result) {
		if (result.success) {
			that.mandateFlows[result.mandateFlow.id] = result.mandateFlow;
			that.mandateFlowTable.selectedObject = result.mandateFlow;
			that.reload();
		}
	});
	return true;
};

/**
 * Save the default mandate flow
 */
ReferrerFlowModule.prototype.saveDefaultMandateFlow = function() {
	var that = this;
	
	var mandateFlow = {};
	mandateFlow.id = this.mandateFlow.id;
	mandateFlow.referrerId = this.referrer.id;
	mandateFlow.defaultStatus = this.inputDefaultStatus.value;
	
	AjaxManager.getJSON('saveDefaultMandateFlow', {
		'mandateFlow' : JSON.stringify(mandateFlow)
	}, function(result) {
		if (result.success) {
			//we don't change the flow using incoming one, just ensure we keep the previous
			that.mandateFlows[that.mandateFlow.id] = that.mandateFlow;
			that.mandateFlowTable.selectedObject = that.mandateFlow;
			that.reload();
		}
	});
	return true;
};

/**
 * Initialization of the mandate flows table
 */
ReferrerFlowModule.prototype.getMandateFlowTable = function() {
	var that = this;
	
	// Mandate flows table
	var mandateFlowTable = new TableModule({
		'selectable' : true,
		'onSelect' : function(mandateFlowId) {
			that.editMandateFlow(mandateFlowId);
		}
	});
	mandateFlowTable.id = 'mandateFlowTable';
	
	// Name column
	var nameCol = new Column('name', I18n.get('name'), '44%');
	nameCol.getText = function(object) {
		return $('<span class="' + (object.inherited ? 'inherited' : '') + '">' + object.name + '</span>');
	};
	mandateFlowTable.columnList.push(nameCol);

	// Created mandate status column
	var createdStatusCol = new Column('createdStatus', I18n.get('referrer.mandateFlow.createdStatus'), '18%', false, true);
	createdStatusCol.clickable = false;
	createdStatusCol.getText = function(object) {
		return $('<input type="checkbox" disabled />').attr('checked', object.createdStatus);
	};
	mandateFlowTable.columnList.push(createdStatusCol);

	// WaitingSignature mandate status column
	var waitingSignatureStatusCol = new Column('waitingSignatureStatus', I18n.get('referrer.mandateFlow.waitingSignatureStatus'), '18%', false, true);
	waitingSignatureStatusCol.clickable = false;
	waitingSignatureStatusCol.getText = function(object) {
		return $('<input type="checkbox" disabled />').attr('checked', object.waitingSignatureStatus);
	};
	mandateFlowTable.columnList.push(waitingSignatureStatusCol);
	
	// Default status column
	if (UserManager.isCreditor(this.referrer)){
		var defaultStatusCol = new Column('defaultStatus', I18n.get('referrer.mandateFlow.defaultStatus'), '8%', false, true);
		defaultStatusCol.clickable = false;
		defaultStatusCol.getText = function(object) {
			return $('<input type="checkbox" disabled />').attr('checked', object.defaultStatus);
		};
		mandateFlowTable.columnList.push(defaultStatusCol);
	}
	
	// Active status column
	var activeStatusCol = new Column('activeStatus', I18n.get('referrer.mandateFlow.activeStatus'), UserManager.isCreditor(this.referrer)?'8%':'16%', false, true);
	activeStatusCol.clickable = false;
	activeStatusCol.getText = function(object) {
		return $('<input type="checkbox" disabled />').attr('checked', object.activeStatus);
	};
	mandateFlowTable.columnList.push(activeStatusCol);
	
	// Delete action column
	var deleteCol = new Column('delete', '', '4%', false, true);
	deleteCol.clickable = false;
	deleteCol.getText = function(object) {
		if (object.inherited) {
			return '';
		}
		if (!UserManager.hasRoles(['MANAGE_MANDATEFLOW'])) {
			return '';
		}
		return $('<i class="icon-remove icon" />').click(function() {
			that.deleteMandateFlow(object.id);
		});
	};
	mandateFlowTable.columnList.push(deleteCol);
	
	return mandateFlowTable;
};
